package demo2;

import java.util.Objects;

class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}

interface IShape{
    public void func();
}

class Test implements IShape{
    @Override
    public void func() {
        System.out.println("hello");
    }
}

public class TestDemo2 {

    public static void main(String[] args) {
        IShape iShape = new Test();
        Object o = iShape;
        IShape shape = (IShape) o;
        shape.func();
    }


    public static void main1(String[] args) {
        Student student1 = new Student("gaobo", 18);
        Student student2 = new Student("gaobo",18);
        System.out.println(student1.equals(student2));

        System.out.println("=======对象的位置。在hashmap上 会使用到");
        System.out.println(student1.hashCode());
        System.out.println(student2.hashCode());
    }
}
